const camera = navigator.MgisScan;

/**
 * 扫描二维码
 */
export const startScan = () => {
  return new Promise((resolve, reject) => {
    if (!camera) return;
    camera.scan(
      {},
      result => {
        console.log('扫描结果', result);
        resolve(result);
      },
      err => {
        console.log('扫描失败', err);
        reject(err);
      }
    );
  });
};

/**
 * 处理扫码结果
 */
export const handleScanResult = (value: string) => {
  return new Promise<Record<string, string>>((resolve, reject) => {
    console.log('处理扫码结果', value);
    if (!value) {
      reject('扫码结果为空');
    }
    if (value.indexOf('https') > -1) {
      reject('二维码异常');
    }
  });
};
